function reverseList(head) {
  if (head == null) return head;
  const list = {};
  let current = list;
  function reverse(node) {
    if (node === null) {
      return;
    }
    reverse(node.next);
    current.val = node.val;
    current.next = {};
    if (node !== head) current = current.next;
  }
  reverse(head);
  current.next = null;
  return list;
}
const list = { val: 1, next: { val: 2, next: { val: 3, next: null } } };
console.log(reverseList(list));
console.log(list);
//会破坏原本结构
function reverseList2(head) {
  let prev = null;
  let curr = head;
  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  return prev;
}
